package com.ellecity06.cwhiskymall.adapter

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.ellecity06.common.ktx.load
import com.ellecity06.cwhiskymall.R
import com.ellecity06.cwhiskymall.bean.response.AppMenuSettingRespone
import com.youth.banner.adapter.BannerAdapter

/**
 * @author ellecity06
 * @time 2024/10/23 16:51
 * @des
 */
class ImageBannerAdapter @JvmOverloads constructor(list: List<AppMenuSettingRespone.SettingWebLayoutVOS.DetailVO>, private val click: ((AppMenuSettingRespone.SettingWebLayoutVOS.DetailVO)->Unit)? = null) :
    BannerAdapter<AppMenuSettingRespone.SettingWebLayoutVOS.DetailVO, ImageBannerAdapter.BannerViewHolder>(list) {

    class BannerViewHolder(var imageView: ImageView) : RecyclerView.ViewHolder(imageView)

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent!!.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    override fun onBindView(holder: BannerViewHolder, data: AppMenuSettingRespone.SettingWebLayoutVOS.DetailVO?, position: Int, size: Int) {
        if (data?.myJumpType==3){
//            holder.imageView.load(holder.imageView.context, )
            holder.imageView.setImageResource(R.mipmap.banner_home_5388)
        }else {
            val image =
                if (data?.customImage!=null&&data.customImage.isNotEmpty()) data.customImage else data?.image?:""
            holder.imageView.load(holder.imageView.context, image)
        }

        if (click != null&&data!=null) {
            holder.imageView.setOnClickListener{
                click.invoke(data)
            }
        }

    }
}